/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Admin_Main.java
 *
 * Created on Dec 3, 2011, 12:49:03 AM
 */
package coursetimetable;
import java.util.*; 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

/**
 *
 * @author mahmoud
 */
public class TimeTableForamt1 extends javax.swing.JFrame {

       String query;
        connect c = new connect();                      //donnect driver class
    procedures prc = new procedures();              //procedures object
    public ResultSet r;                             //data container
    /** Creates new form Admin_Main */
    public TimeTableForamt1() {
        
        this.setLocation(200, 100);
        this.setResizable(false);
        
        initComponents();
          query = prc.GetClassrooms();                            //gets the query to excute
        r = c.connection(query);
        try {
            while(r.next())
            {
                if(Integer.parseInt(r.getString(1))>= 900000)
                {
                    jComboBox2.addItem(r.getString(2)) ;
                }
                else 
                    jComboBox1.addItem(r.getString(2)) ;
               
            }
        } catch (SQLException ex) {
            Logger.getLogger(TimeTableForamt1.class.getName()).log(Level.SEVERE, null, ex);
        }
        
      
       
         //this.Professor_Tap_Button_Visble(true);
    }
  
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jComboBox2 = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jComboBox5 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jComboBox9 = new javax.swing.JComboBox();
        jComboBox8 = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 500));
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jComboBox2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox2.setName("jComboBox2"); // NOI18N
        jComboBox2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox2MouseClicked(evt);
            }
        });
        jPanel2.add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 390, 170, 50));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(coursetimetable.CourseTimeTableApp.class).getContext().getResourceMap(TimeTableForamt1.class);
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setActionCommand(resourceMap.getString("jButton2.actionCommand")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jPanel2.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 390, 200, 50));

        jComboBox1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox1MouseClicked(evt);
            }
        });
        jPanel2.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 340, 170, 50));

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("jButton1.toolTipText")); // NOI18N
        jButton1.setActionCommand(resourceMap.getString("jButton1.actionCommand")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jPanel2.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 340, 200, 50));

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });
        jPanel2.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 273, 220, 50));

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel5.setName("jLabel5"); // NOI18N
        jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 390, 170, 50));

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel4.setName("jLabel4"); // NOI18N
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 340, 170, 50));

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Saturday", null, null, null, null, null, null, null, null},
                {"Sunday", null, null, null, null, null, null, null, null},
                {"Monday", null, null, null, null, null, null, null, null},
                {"Tueesday", null, null, null, null, null, null, null, null},
                {"Wednesday", null, null, null, null, null, null, null, null},
                {"thursday", null, null, null, null, null, null, null, null}
            },
            new String [] {
                "", "8:00-10:00", "10:00-12:00", "12:00-12:30", "12:30-2:30", "2:30-4:30", "4:30-6:30", "6:30-8:30", "8:30-10:30"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.setRowHeight(40);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
        jTable1.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N
        jTable1.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable1.columnModel.title5")); // NOI18N
        jTable1.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable1.columnModel.title7")); // NOI18N
        jTable1.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("jTable1.columnModel.title8")); // NOI18N

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 690, 450));

        jLabel8.setIcon(resourceMap.getIcon("jLabel8.icon")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel8.setName("jLabel8"); // NOI18N
        jPanel2.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 700, 450));

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jPanel2.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 290, 210, -1));

        jTabbedPane1.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jComboBox5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox5.setName("jComboBox5"); // NOI18N
        jComboBox5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox5MouseClicked(evt);
            }
        });
        jPanel3.add(jComboBox5, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 310, 170, 50));

        jComboBox3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox3.setName("jComboBox3"); // NOI18N
        jComboBox3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox3MouseClicked(evt);
            }
        });
        jPanel3.add(jComboBox3, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 240, 170, 50));

        jComboBox4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox4.setName("jComboBox4"); // NOI18N
        jComboBox4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox4MouseClicked(evt);
            }
        });
        jPanel3.add(jComboBox4, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 160, 170, 50));

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel11.setName("jLabel11"); // NOI18N
        jPanel3.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 310, 170, 50));

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel6.setName("jLabel6"); // NOI18N
        jPanel3.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 240, 170, 50));

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel7.setName("jLabel7"); // NOI18N
        jPanel3.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 160, 170, 50));

        jLabel10.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel10.setName("jLabel10"); // NOI18N
        jPanel3.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 700, 450));

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel16.setName("jLabel16"); // NOI18N
        jPanel4.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 170, 130, 50));

        jComboBox9.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox9.setName("jComboBox9"); // NOI18N
        jComboBox9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox9MouseClicked(evt);
            }
        });
        jPanel4.add(jComboBox9, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 240, 220, 50));

        jComboBox8.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jComboBox8.setName("jComboBox8"); // NOI18N
        jComboBox8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox8MouseClicked(evt);
            }
        });
        jPanel4.add(jComboBox8, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 170, 50));

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel14.setName("jLabel14"); // NOI18N
        jPanel4.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 40, 130, 50));

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });
        jPanel4.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 180, 170, 60));

        jLabel15.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel15.setName("jLabel15"); // NOI18N
        jPanel4.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 700, 450));

        jTabbedPane1.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        jPanel1.add(jTabbedPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 100, 700, 490));

        jPanel7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel7.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel7.setName("jPanel7"); // NOI18N
        jPanel7.setLayout(null);

        jLabel1.setFont(resourceMap.getFont("YearLabel.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("YearLabel.text")); // NOI18N
        jLabel1.setName("YearLabel"); // NOI18N
        jPanel7.add(jLabel1);
        jLabel1.setBounds(10, 20, 140, 40);

        jLabel2.setFont(resourceMap.getFont("Yaer20_label.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("Yaer20_label.text")); // NOI18N
        jLabel2.setName("Yaer20_label"); // NOI18N
        jPanel7.add(jLabel2);
        jLabel2.setBounds(150, 20, 90, 40);

        jLabel9.setIcon(resourceMap.getIcon("jLabel9.icon")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N
        jPanel7.add(jLabel9);
        jLabel9.setBounds(0, 0, 260, 70);

        jPanel1.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 20, 260, 70));

        jLabel3.setIcon(resourceMap.getIcon("jLabel3.icon")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(4, 0, 840, 590));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked
        
        
}//GEN-LAST:event_jTabbedPane1MouseClicked

private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox1MouseClicked
// TODO add your handling code here:
     
}//GEN-LAST:event_jComboBox1MouseClicked

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        try {
            // TODO add your handling code here:
                    
                    int Room_Index=jComboBox1.getSelectedIndex();
                    List<Day> Day_List = new ArrayList<Day>();
                     query = prc.GetAllWeek();                            //gets the query to excute
                    r = c.connection(query);
                    try {
                        while(r.next())
                        {
                            Day d= new Day();
                            d.Day_id=Integer.parseInt( r.getString(1));
                            d.Day_Name= r.getString(2);
                            Day_List.add(d);
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(TimeTableForamt1.class.getName()).log(Level.SEVERE, null, ex);
                    }
                  
                    
                    Graph_Matrix g = new Graph_Matrix();
                        //array of courses names for graph draw
                        String [] course_name = new String[g.getCourses().length];
                        for (int i = 0; i < course_name.length; i++) {
                            course_name[i]=g.getCourses()[i].name;
                        }
                        
                              Weight W = new Weight(g.getG_Matrix(), g.getCourses());            
                       /// JFrame tt=new JFrame();            
                      //  tt.setLocation(400, 100);
                      //  tt.setSize(800, 500);
                     //   tt.getContentPane().add(new JScrollPane(conflict.DrawGraph(course_name,W.No_of_Conflicts, g.getG_Matrix())));
                     //   tt.setVisible(true);
                   
                        Coloring_Algorithm coloring = new Coloring_Algorithm(g.getCourses(),g.getG_Matrix());
                    
                    
                    Table_Cell [] [] Algo_Cell_Arr= coloring.Cells;
                    int day_no=Algo_Cell_Arr.length;
                    int slots_no=Algo_Cell_Arr[0].length;
                    
                    int Table_Slot=0;
                    for (int i=0;i< slots_no;i++)
                    {       
                        Table_Slot=i;
                        if(Table_Slot>=2)
                        {
                            Table_Slot++;
                        }
                                
                        for (int j=0 ;j<day_no;j++)
                        {
                            Algo_Cell_Arr[j][i].Set_Day_Name(Day_List);
                            if("Saturday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                if(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 0, Table_Slot+1); 
                                }
                                else 
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C.name+" "+Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].type, 0, Table_Slot+1);   
                            }
                            else if("Sunday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 1, Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C.name+" "+Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].type, 1, Table_Slot+1);   
                            }
                            else if("Monday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 2, Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C.name+" "+Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].type, 2, Table_Slot+1);   
                            }
                            else if("Tuesday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 3, Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C.name+" "+Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].type, 3, Table_Slot+1);   
                            }
                            else if("Wednesday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 4, Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C.name+" "+Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].type, 4, Table_Slot+1);   
                            }
                            else  if("Thursday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 5, Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].C.name+" "+Algo_Cell_Arr[j][i].lecture_rooms[Room_Index].type, 5, Table_Slot+1);   
                            }
                        }
                    }
                    for(int z =0 ;z<coloring.unassigned_courses.size();z++)
                    {
                        jComboBox4.addItem(coloring.unassigned_courses.get(z).name);
                       
                    }
                    for(int z =0 ;z<coloring.unassigned_sections.size();z++)
                    {
                        jComboBox3.addItem(coloring.unassigned_sections.get(z).name);
                       
                    }
                    for(int z =0 ;z<coloring.unassigned_labs.size();z++)
                    {
                        jComboBox5.addItem(coloring.unassigned_labs.get(z).name);
                       
                    }
        } catch (SQLException ex) {
            Logger.getLogger(TimeTableForamt1.class.getName()).log(Level.SEVERE, null, ex);
        }
        
}//GEN-LAST:event_jButton1MouseClicked

private void jComboBox2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox2MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox2MouseClicked

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO add your handling code here:
    try {
            // TODO add your handling code here:
                    
        
                   List<Day> Day_List = new ArrayList<Day>();
                     query = prc.GetAllWeek();                            //gets the query to excute
                    r = c.connection(query);
                    try {
                        while(r.next())
                        {
                            Day d= new Day();
                            d.Day_id=Integer.parseInt( r.getString(1));
                            d.Day_Name= r.getString(2);
                            Day_List.add(d);
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(TimeTableForamt1.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    int Lab_Room_Index=jComboBox2.getSelectedIndex();
                    
                    Graph_Matrix g = new Graph_Matrix();
                        //array of courses names for graph draw
                        String [] course_name = new String[g.getCourses().length];
                        for (int i = 0; i < course_name.length; i++) {
                            course_name[i]=g.getCourses()[i].name;
                        }
                        
                              Weight W = new Weight(g.getG_Matrix(), g.getCourses());            
                       /// JFrame tt=new JFrame();            
                      //  tt.setLocation(400, 100);
                      //  tt.setSize(800, 500);
                     //   tt.getContentPane().add(new JScrollPane(conflict.DrawGraph(course_name,W.No_of_Conflicts, g.getG_Matrix())));
                     //   tt.setVisible(true);
                   
                        Coloring_Algorithm coloring = new Coloring_Algorithm(g.getCourses(),g.getG_Matrix());
                    
                    
                    Table_Cell [] [] Algo_Cell_Arr= coloring.Cells;
                    int day_no=Algo_Cell_Arr.length;
                    int slots_no=Algo_Cell_Arr[0].length;
                    
                   int  Table_Slot=0;
                    for (int i=0;i< slots_no;i++)
                    {
                         Table_Slot=i;
                        if(Table_Slot>=2)
                        {
                            Table_Slot++;
                        }
                        for (int j=0 ;j<day_no;j++)
                        {
                            Algo_Cell_Arr[j][i].Set_Day_Name(Day_List);
                            if("Saturday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                if(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 0,  Table_Slot+1); 
                                }
                                else 
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C.name, 0,  Table_Slot+1);   
                            }
                            else if("Sunday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 1,  Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C.name, 1,  Table_Slot+1);   
                            }
                            else if("Monday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 2,  Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C.name, 2,  Table_Slot+1);   
                            }
                            else if("Tuesday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 3,  Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C.name, 3,  Table_Slot+1);   
                            }
                            else if("Wednesday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 4,  Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C.name, 4,  Table_Slot+1);   
                            }
                            else  if("Thursday".equals(Algo_Cell_Arr[j][i].Day_Name))
                            {
                                 if(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C==null)
                                {
                                   jTable1.setValueAt(" ", 5,  Table_Slot+1); 
                                }
                                 else
                             jTable1.setValueAt(Algo_Cell_Arr[j][i].lab_rooms[Lab_Room_Index].C.name, 5,  Table_Slot+1);   
                            }
                        }
                    }
        } catch (SQLException ex) {
            Logger.getLogger(TimeTableForamt1.class.getName()).log(Level.SEVERE, null, ex);
        }
    
}//GEN-LAST:event_jButton2MouseClicked

private void jComboBox3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox3MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox3MouseClicked

private void jComboBox4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox4MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox4MouseClicked

private void jComboBox5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox5MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox5MouseClicked

private void jComboBox8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox8MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox8MouseClicked

private void jComboBox9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox9MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox9MouseClicked

private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        try {
            // TODO add your handling code here:   // Exam Button
                Graph_Matrix g = new Graph_Matrix();
                                    //array of courses names for graph draw
                                    String [] course_name = new String[g.getCourses().length];
                                    for (int i = 0; i < course_name.length; i++) {
                                        course_name[i]=g.getCourses()[i].name;
                                    }
                                    
                                          Weight W = new Weight(g.getG_Matrix(), g.getCourses());            
                                   // JFrame tt=new JFrame();            
                                  //  tt.setLocation(400, 100);
                                  //  tt.setSize(800, 500);
                                 //   tt.getContentPane().add(new JScrollPane(conflict.DrawGraph(course_name,W.No_of_Conflicts, g.getG_Matrix())));
                                 //   tt.setVisible(true);
                                int Selected_index=0 ;
                                    //Coloring_Algorithm coloring = new Coloring_Algorithm(g.getCourses(),g.getG_Matrix());
                              Exam E = new Exam(g.getG_Matrix(), g.getCourses());
                                    List<Exam_table>   e = E.exams;
                                  for(int i=0;i<e.size();i++)
                                  {
                                      jComboBox8.addItem(e.get(i).day_ID);
                                  }
                                  Selected_index=jComboBox8.getSelectedIndex();
                                  for(int i=0;i<e.get(Selected_index).courses.size();i++)
                                  {
                                      jComboBox9.addItem(e.get(Selected_index).courses.get(i).name);
                                  }
                                    
        } catch (SQLException ex) {
            Logger.getLogger(TimeTableForamt1.class.getName()).log(Level.SEVERE, null, ex);
        }
    
}//GEN-LAST:event_jButton3MouseClicked

private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
// TODO add your handling code here:    / Draw Graph
    Graph_Matrix g = new Graph_Matrix();
                                    //array of courses names for graph draw
                                    String [] course_name = new String[g.getCourses().length];
                                    for (int i = 0; i < course_name.length; i++) {
                                        course_name[i]=g.getCourses()[i].name;
                                    }
                                    
                                          Weight W = new Weight(g.getG_Matrix(), g.getCourses());            
                                   JFrame tt=new JFrame();            
                                    tt.setLocation(400, 100);
                                    tt.setSize(800, 500);
                                    tt.getContentPane().add(new JScrollPane(conflict.DrawGraph(course_name,W.No_of_Conflicts, g.getG_Matrix())));
                                    tt.setVisible(true);
}//GEN-LAST:event_jButton5MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TimeTableForamt1().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox8;
    private javax.swing.JComboBox jComboBox9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
